#include <linux/timer.h>
#include <linux/module.h>

#define SEC_COUNT 5
#define MS_COUNT 200

struct timer_list slam_timer;
unsigned long slam_data = SEC_COUNT;

void slam_timer_function(unsigned long data)
{
	printk("<1>I'm in timer,data=%lu\n",data);
	/* every SEC_COUNT seconds call an timer interrupt
	mod_timer(&slam_timer, jiffies + HZ * SEC_COUNT);
	*/

	// every MS_COUNT ms call an timer interrupt
	mod_timer(&slam_timer, jiffies + msecs_to_jiffies(MS_COUNT));
}

int init_module(void)
{
	printk("<1>Install timer module!\n");
	/* every SEC_COUNT seconds call an timer interrupt
	init_timer(&slam_timer);
	slam_timer.expires = jiffies + HZ * SEC_COUNT;
	slam_timer.data = slam_data;
	slam_timer.function = slam_timer_function;

	add_timer(&slam_timer);
	*/

	// every MS_COUNT ms call an timer interrupt
	setup_timer(&slam_timer, slam_timer_function, slam_data);
	mod_timer(&slam_timer, jiffies + msecs_to_jiffies(MS_COUNT));

	return 0;
}

void cleanup_module(void)
{
	printk("<1>Remove timer module!\n");
	del_timer(&slam_timer);
}
